package com.zmj.sy.mom.srv.aps.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmj.sy.mom.srv.aps.bean.entity.mes.*;
import com.zmj.sy.mom.srv.aps.bean.entity.order.ApsWorkDetail;
import com.zmj.sy.mom.srv.aps.bean.entity.order.ApsWorkOrder;
import com.zmj.sy.mom.srv.aps.bean.entity.order.OrderBom;
import com.zmj.sy.mom.srv.aps.bean.entity.resource.PhaseBoss;
import com.zmj.sy.mom.srv.aps.bean.entity.third.SinoCamPushPlan;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.CommonPage;
import com.zmj.sy.mom.srv.aps.bean.vo.partexcept.*;
import com.zmj.sy.mom.srv.aps.bean.vo.partexceptdetail.PartExceptDetailAddReqVo;
import com.zmj.sy.mom.srv.aps.feign.WmsApiClient;
import com.zmj.sy.mom.srv.aps.mapper.*;
import com.zmj.sy.mom.srv.aps.utils.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Service
public class PartExceptService {
    private final ApsOrderMapper apsOrderMapper;
    private final PartExceptMapper partExceptMapper;
    private final  PartService  partService;
    private final PartExceptDetailMapper partExceptDetailMapper;
    private final ApsWorkDetailMapper apsWorkDetailMapper;
    private final OrderBomMapper orderBomMapper;
    private final OrderMapper orderMapper;
    private final PhaseBossMapper phaseBossMapper;
    private final PartUtilService partUtilService;
    private final WorkDetailTaskMapper workDetailTaskMapper;
    private final SinoCamPushPlanMapper sinoCamPushPlanMapper;
    private final WmsApiClient wmsApiClient;
    private final ApsWorkOrderMapper apsWorkOrderMapper;
    /**
     * @param plmId
     * @param prePhaseCode
     * @param phaseCode
     * @param phaseSeq
     * @param exceptCount
     * @param userCode
     * @param oldWorkDetailId
     */
    @Transactional
    public void createPartExcept(String constructNo,String plmId, String prePhaseCode, String phaseCode, Integer phaseSeq, Integer exceptCount,
                                 String userCode, Integer oldWorkDetailId, String groupCode, String stationCode, String plateCode) {

        if (exceptCount > 0) {
            OrderBom bom = orderBomMapper.lambdaQuery()
                    .eq(OrderBom::getPlmId, plmId)
                    .last("limit 1")
                    .one();
//            Order order = orderMapper.selectById(bom.getOrderId());
           /* PhaseBoss phase = phaseBossMapper.lambdaQuery().eq(PhaseBoss::getPhaseCode, prePhaseCode).last("limit 1")
                    .one();*/
            PartExcept pe = new PartExcept();
            pe.setWorkDetailId(oldWorkDetailId);
            pe.setMaterCode(bom.getMaterCode());
            pe.setMaterName(bom.getMaterName());
            pe.setDrawing(bom.getDrawing());
            pe.setConstructCode(constructNo);
            pe.setExceptCount(exceptCount);
            pe.setPlmId(plmId);
            pe.setBreakCount(0);
            pe.setFinishCount(0);
            pe.setUserCode(userCode);
            pe.setPhaseCode(phaseCode);
            pe.setPhaseSeq(phaseSeq);
            pe.setPrePhaseCode(prePhaseCode);
            pe.setStatus(2);
            pe.setPlateCode(plateCode);
            pe.setGroupCode(groupCode);
            pe.setStationCode(stationCode);
            partExceptMapper.insert(pe);    // 添加零件异常日志
        }





      /*  PartExceptDetail ped = new PartExceptDetail();
        ped.setPid(null);
        ped.setPartExceptId(pe.getId());
        ped.setPhaseCode(pe.getNextPhaseCode());
        ped.setPhaseSeq(pe.getNextPhaseSeq());
        ped.setStatus(1);
        ped.setBeforeCount(pe.getExceptCount());
        ped.setProcessCount(0);
        ped.setAfterCount(pe.getExceptCount());
        ped.setUserCode(reqVo.getUserCode());
        partExceptDetailMapper.insert(ped);*/

    }

    public CommonPage<PartExceptPageResVo> list(PartExceptPageReqVo reqVo) {
       /*  if (StringUtils.isBlank(reqVo.getUserCode())) {
            reqVo.setUserCode(ServletUtils.getHeadParameter("worker"));
        }*/
        LambdaQueryWrapper<PartExcept> query = new LambdaQueryWrapper();
        query.like(StringUtils.isNotBlank(reqVo.getPlmId()),PartExcept::getPlmId, reqVo.getPlmId());
        query.like(StringUtils.isNotBlank(reqVo.getGroupCode()),PartExcept::getGroupCode, reqVo.getGroupCode());
        query.like(StringUtils.isNotBlank(reqVo.getPhaseCode()),PartExcept::getPrePhaseCode, reqVo.getPhaseCode());
        query.like(StringUtils.isNotBlank(reqVo.getPlateCode()),PartExcept::getPlateCode, reqVo.getPlateCode());
        query.like(StringUtils.isNotBlank(reqVo.getConstructCode()),PartExcept::getConstructCode, reqVo.getConstructCode());
        if(reqVo.getStatus()!=null){
         query.eq(PartExcept::getStatus, reqVo.getStatus());
        }else{
            query.in(PartExcept::getStatus, 1, 2, 4); // 查询待判定，返修中，已报废
        }
        Page<PartExcept> page = partExceptMapper.selectPage(reqVo.toPage(), query);
        List<PartExceptPageResVo> l = page.getRecords()
                .stream()
                .map(e -> MkBeanUtils.copyProperties(e, PartExceptPageResVo.class))
                .collect(Collectors.toList());
        CommonPage<PartExceptPageResVo> pageRes = CommonPage.restPage(page.getTotal(), l);
        pageRes.setPages(page.getPages());
        pageRes.setSize(page.getSize());
        pageRes.setPage(page.getCurrent());
        return pageRes;


    }

    @Transactional
    public void addDetail(PartExceptDetailAddReqVo reqVo) {
        if (StringUtils.isBlank(reqVo.getUserCode())) {
            reqVo.setUserCode(ServletUtils.getHeadParameter("worker"));
        }

        if (reqVo.getProcessCount() < 1) {
            throw SyExceptionUtils.e("处理数量不能小于1");
        }

        PartExcept partExcept = partExceptMapper.selectById(reqVo.getPartExceptId());
        PartExceptDetail detail = partExceptDetailMapper.lambdaQuery().eq(PartExceptDetail::getPartExceptId, partExcept.getId()).one();
        PhaseBoss phase = phaseBossMapper.lambdaQuery().eq(PhaseBoss::getPhaseCode, reqVo.getExceptPhase()).last("limit 1")
                .one();

        if (ObjectUtils.isEmpty(detail)) {
            detail = new PartExceptDetail();
            detail.setPartExceptId(partExcept.getId());
            detail.setMaterCode(partExcept.getPlmId());
            detail.setMaterName(partExcept.getMaterName());
            detail.setPrePhaseCode(partExcept.getPrePhaseCode());
            detail.setPhaseCode(partExcept.getPhaseCode());
            detail.setPhaseSeq(partExcept.getPhaseSeq());
        }
        detail.setExceptPhase(reqVo.getExceptPhase());
        detail.setDealPhase(reqVo.getDealPhase());
        detail.setRemark(reqVo.getRemark());
        detail.setImg1(reqVo.getImg1());
        detail.setImg2(reqVo.getImg2());
        detail.setImg3(reqVo.getImg3());
        detail.setExceptType(reqVo.getExceptType());
        detail.setProcessCount(reqVo.getProcessCount());
        detail.setUserCode(reqVo.getUserCode());

        if (partExcept.getExceptCount() > reqVo.getProcessCount()) {
            PartExcept partExceptnew = new PartExcept();
            BeanUtil.copyProperties(partExcept, partExceptnew, "id");
            partExceptnew.setExceptCount(partExcept.getExceptCount() - reqVo.getProcessCount());
            partExceptMapper.insert(partExceptnew);
        }
        partExcept.setExceptCount(reqVo.getProcessCount());
        if (reqVo.getExceptType() == 4) {
            partExcept.setBreakCount(0);
            partExcept.setFinishCount(reqVo.getProcessCount());
            partExcept.setStatus(3);
            partExcept.setRemark("工件正常");
            detail.setStatus(3);
            partExceptDetailMapper.insert(detail);
            //正常业务处理
            Part nextPart = partService.getPart(partExcept.getConstructCode(),  partExcept.getPlmId(), partExcept.getPhaseCode());
            if (ObjectUtils.isNotEmpty(nextPart)) {
                if (nextPart.getFailCount() < reqVo.getProcessCount()) {
                    throw SyExceptionUtils.e(String.format("零件%s待加工工序%s异常零件不足", partExcept.getPlmId(), partExcept.getPhaseCode()));
                }
            } else {
                throw SyExceptionUtils.e(String.format("零件%s待加工工序%s异常零件不存在", partExcept.getPlmId(), partExcept.getPhaseCode()));
            }
            nextPart.setPartCount(nextPart.getPartCount() + reqVo.getProcessCount());
            nextPart.setFailCount(nextPart.getFailCount() - reqVo.getProcessCount());
            partService.updateById(nextPart);
            WorkRecord workRecord = new WorkRecord();
            workRecord.setWorkStaffCode(reqVo.getUserCode());
            workRecord.setStationCode("确认工位");
            partUtilService.createPartLog(4, nextPart, reqVo.getProcessCount(), -reqVo.getProcessCount()
                    , null, workRecord, null);
        } else if (reqVo.getExceptType() == 3) {
            if (ObjectUtils.isNotEmpty(phase)) {
                partExcept.setUserCode(phase.getBossCode());
            } else {
                partExcept.setUserCode(reqVo.getExceptPhase());
            }
            partExcept.setRemark("转移人员" + partExcept.getUserCode());
        } else if (reqVo.getExceptType() == 2) {
            partExcept.setStatus(4);
            partExcept.setBreakCount(reqVo.getProcessCount());
            partExcept.setRemark("确认报废");
            detail.setStatus(3);
            partExceptDetailMapper.insert(detail);

            Part nextPart = partService.getPart(partExcept.getConstructCode(),  partExcept.getPlmId(), partExcept.getPhaseCode());
            if (ObjectUtils.isNotEmpty(nextPart)) {
                if (nextPart.getFailCount() < reqVo.getProcessCount()) {
                    throw SyExceptionUtils.e(String.format("零件%s待加工工序%s异常零件不足", partExcept.getPlmId(), partExcept.getPhaseCode()));
                }
            } else {
                throw SyExceptionUtils.e(String.format("零件%s待加工工序%s异常零件不存在", partExcept.getPlmId(), partExcept.getPhaseCode()));
            }
            int damageCount = nextPart.getDamageCount();
            nextPart.setDamageCount(damageCount + reqVo.getProcessCount());
            nextPart.setFailCount(nextPart.getFailCount() - reqVo.getProcessCount());
            partService.updateById(nextPart);
            WorkRecord workRecord = new WorkRecord();
            workRecord.setWorkStaffCode(reqVo.getUserCode());
            workRecord.setStationCode("确认报废");
            partUtilService.createPartLog(3, nextPart, 0, -reqVo.getProcessCount()
                    , null, workRecord, null);
            this.updateWorkDetail(partExcept.getWorkDetailId(), reqVo.getProcessCount());

            // 重新生成工单
        } else if (reqVo.getExceptType() == 1) {
            partExcept.setStatus(2);
            partExcept.setRemark("返修中");
            detail.setStatus(2);
            partExceptDetailMapper.insert(detail);
        }
        partExceptMapper.updateById(partExcept);

    }

    /**
     * 将当前及当前以前的工序，计划数量增加报废的数量，并更新计划为加工中
     *
     * @param workDetailId
     */
    private void updateWorkDetail(Integer workDetailId, Integer breakCount) {
        ApsWorkDetail workDetail = apsWorkDetailMapper.selectById(workDetailId);
        List<ApsWorkDetail> preApsWorkDetail = apsWorkDetailMapper.lambdaQuery()
                .eq(ApsWorkDetail::getApsWorkOrderId, workDetail.getApsWorkOrderId()).le(ApsWorkDetail::getPhaseSeq, workDetail.getPhaseSeq()).list();
        ApsWorkDetail qgDetail = null;
        for (ApsWorkDetail item : preApsWorkDetail) {
            item.setTotalCount(item.getTotalCount().add(new BigDecimal(breakCount)));
            item.setStatus(3);
            apsWorkDetailMapper.updateById(item);
            if (item.getPhaseCode().equals("JG") || item.getPhaseCode().equals("HG")) {
                qgDetail = item;
            }
        }

        SinoCamPushPlan plan = sinoCamPushPlanMapper.lambdaQuery().eq(SinoCamPushPlan::getNestPlanId, qgDetail.getId()).last("limit 1").one();
        if (ObjectUtils.isNotEmpty(plan)) {
            SinoCamPushPlan maxIndex = sinoCamPushPlanMapper.lambdaQuery().select(SinoCamPushPlan::getMyindex).eq(SinoCamPushPlan::getOrderId, plan.getOrderId()).orderByDesc(SinoCamPushPlan::getMyindex).last("limit 1").one();
            SinoCamPushPlan newPlan = new SinoCamPushPlan();
            BeanUtils.copyProperties(plan, newPlan);
            newPlan.setId(null);
            newPlan.setStatus(1);
            newPlan.setPlanFinishAmount(new BigDecimal(0));
            newPlan.setNeedDate(LocalDateTime.now());
            newPlan.setPlanAmount(new BigDecimal(breakCount));
            newPlan.setMyindex(maxIndex.getMyindex() + 1);
            newPlan.setState("N");
            sinoCamPushPlanMapper.insert(newPlan);
        }


    }

    @Transactional
    public void partCheck(PartCheckReqVo reqVo) {
        /*if(StringUtils.isBlank( reqVo.getUserCode())){
            reqVo.setUserCode(ServletUtils.getHeadParameter("worker"));
        }*/
        PartExcept partExcept = partExceptMapper.selectById(reqVo.getPartExceptId());
//        PartExceptDetail detail = partExceptDetailMapper.lambdaQuery().eq(PartExceptDetail::getPartExceptId, partExcept.getId()).one();
        partExcept.setFinishCount(partExcept.getFinishCount() + reqVo.getFinishCount());
        if (partExcept.getFinishCount() == partExcept.getExceptCount()) {
            partExcept.setRemark("返修成功");
            partExcept.setStatus(3);
        } else {
            partExcept.setStatus(2);
        }
        partExcept.setUserCode(reqVo.getUserCode());
        partExceptMapper.updateById(partExcept);
        //正常业务处理
        Part nextPart = partService.getPart(partExcept.getConstructCode(), partExcept.getPlmId(), partExcept.getPhaseCode());
        if (ObjectUtils.isNotEmpty(nextPart)) {
            if (nextPart.getFailCount() < reqVo.getFinishCount()) {
                throw SyExceptionUtils.e(String.format("零件%s待加工工序%s异常零件不足", partExcept.getPlmId(), partExcept.getPhaseCode()));
            }
        } else {
            throw SyExceptionUtils.e(String.format("零件%s待加工工序%s异常零件不存在", partExcept.getPlmId(), partExcept.getPhaseCode()));
        }
        nextPart.setPartCount(nextPart.getPartCount() + reqVo.getFinishCount());
        nextPart.setFailCount(nextPart.getFailCount() - reqVo.getFinishCount());
        partService.updateById(nextPart);
        //装盘
        if (StrUtil.isNotEmpty(reqVo.getPalletNumber())) {
            partUtilService.putPallet(reqVo.getFinishCount(), reqVo.getPalletNumber(), nextPart);
            wmsApiClient.partPage(reqVo.getPalletNumber());
        }
       if(WorkshopProp.KJ_PHASE_CODE.equalsIgnoreCase(partExcept.getPhaseCode())){
           // 如果是库检 ，要能够自动完工
           ApsWorkDetail apsWorkDetail = apsWorkDetailMapper.selectById(partExcept.getWorkDetailId());
           ApsWorkDetail one = apsWorkDetailMapper.lambdaQuery().eq(ApsWorkDetail::getApsWorkOrderId, apsWorkDetail.getApsWorkOrderId())
                   .eq(ApsWorkDetail::getPhaseCode, WorkshopProp.KJ_PHASE_CODE).last("LIMIT 1").one();
           if (ObjectUtils.isNotEmpty(one)){
               apsWorkDetailMapper.lambdaUpdate().eq(ApsWorkDetail::getId, one.getId())
                       .set(ApsWorkDetail::getActualEndDateTime, LocalDateTime.now())
                       .setSql("finish_count=finish_count+"+reqVo.getFinishCount()).update();
               if (one.getFinishCount().intValue()+reqVo.getFinishCount() >= one.getTotalCount().intValue()) {
                   apsWorkDetailMapper.lambdaUpdate().eq(ApsWorkDetail::getId, one.getId())
                           .set(ApsWorkDetail::getStatus, 4).update();
               }
           }
           ApsWorkOrder apsWorkOrder = apsWorkOrderMapper.selectById(apsWorkDetail.getApsWorkOrderId());
           partUtilService.updateOrderState(apsWorkOrder, null,reqVo.getFinishCount());

       }
        //  添加零件分拣报工记录
        WorkDetailTask task = workDetailTaskMapper.lambdaQuery()
                .eq(WorkDetailTask::getPlmid, partExcept.getPlmId())
                .last("limit 1").one();
        reqVo.setUserCode(org.springframework.util.StringUtils.hasText(reqVo.getUserCode()) ? reqVo.getUserCode() : SySecurityUtils.getUserCode());
        WorkRecord workRecord = partUtilService.complatePartReport(task.getOrderCode(), partExcept.getGroupCode(), partExcept.getStationCode(), 2, 2, partExcept.getPlmId(),
                partExcept.getPrePhaseCode(), null, reqVo.getFinishCount(), 0, reqVo.getUserCode(), null, partExcept.getWorkDetailId(), null, null, partExcept.getPlateCode());
        partUtilService.createPartLog(4, nextPart, partExcept.getExceptCount(), -reqVo.getFinishCount()
                , null, workRecord, null);


    }

    public PartExceptDetailResVo getExceptDetail(PartExceptDetailReqVo reqVo) {
        PartExcept partExcept = partExceptMapper.selectById(reqVo.getPartExceptId());
        Part nextPart = partService.getPart(partExcept.getConstructCode(), partExcept.getPlmId(), partExcept.getPhaseCode());
        List<PhaseBoss> phase = phaseBossMapper.lambdaQuery().eq(PhaseBoss::getBossCode, partExcept.getUserCode()).list();
        List<String> collect = phase.stream().map(PhaseBoss::getPhaseCode).collect(Collectors.toList());
        PartExceptDetailResVo vo = new PartExceptDetailResVo();
        BeanUtils.copyProperties(partExcept, vo);
        vo.setWorkChain(nextPart.getWorkChain());
        vo.setPhaseChief(collect);
        vo.setPartExceptId(partExcept.getId());
        return vo;
    }

    public void partExceAll() {
        List<PartExcept> list = partExceptMapper.lambdaQuery().eq(PartExcept::getStatus, 1).list();
        for (PartExcept one : list) {
            partExceOne(one.getId());
        }
    }

    public void partExceOne(Integer id) {
        // 查询异常零件信息
        PartExcept partExcept = partExceptMapper.selectById(id);
        // 查询该异常件的计划
        ApsWorkDetail apsWorkDetail = apsWorkDetailMapper.selectById(partExcept.getWorkDetailId());

        // 查询异常件的下一工序的计划
        ApsWorkDetail apsWorkDetailNext = apsWorkDetailMapper.lambdaQuery().eq(ApsWorkDetail::getApsWorkOrderId, apsWorkDetail.getApsWorkOrderId())
                .eq(ApsWorkDetail::getPhaseSeq, apsWorkDetail.getPhaseSeq() + 1).one();
        if (WorkshopProp.KJ_PHASE_CODE.equals(apsWorkDetailNext.getPhaseCode())) {
         /*   LambdaQueryWrapper<Part> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Part::getPlmId, apsWorkDetailNext.getMaterNo());
                queryWrapper.eq(Part::getPhaseCode, WorkshopProp.KJ_PHASE_CODE);
            // 添加下道工序的零件
            Part nextPart = partMapper.selectOne(queryWrapper);
            if (nextPart == null) {
                nextPart = new Part();
                nextPart.setPlmId(apsWorkDetailNext.getMaterNo());
                nextPart.setPhaseCode(WorkshopProp.KJ_PHASE_CODE);
                nextPart.setPhaseName(apsWorkDetailNext.getPhaseName());
                nextPart.setPhaseSeq(apsWorkDetailNext.getPhaseSeq());
                nextPart.setWorkGroup(apsWorkDetailNext.getGroupCode());
                nextPart.setPrePhaseCode(apsWorkDetail.getPhaseCode());
                nextPart.setWorkChain(null);
                nextPart.setFailCount(0);
                nextPart.setPartCount(partExcept.getExceptCount());
                nextPart.setPartType(2);
                partMapper.insert(nextPart);
            } else {
                nextPart.setPartCount(nextPart.getPartCount() + partExcept.getExceptCount());
                nextPart.setFailCount(nextPart.getFailCount() + 0);
                partMapper.updateById(nextPart);
            }
            partExcept.setRemark(partExcept.getExceptCount()+"生成任务数量");
            partExcept.setStatus(2);
            partExceptMapper.updateById(partExcept);*/
            return;
        }

        // 查询下一工序计划的任务
        List<WorkDetailTask> workDetailTaskList = workDetailTaskMapper.lambdaQuery().eq(WorkDetailTask::getApsWorkDetailId, apsWorkDetailNext.getId()).list();
        // 计算数量是否相等
        int totalCount = 0;
        for (WorkDetailTask task : workDetailTaskList) {
            totalCount = totalCount + task.getTotalCount();
        }
        int left = apsWorkDetailNext.getTotalCount().subtract(new BigDecimal(totalCount)).intValue();
        if (left > 0) {
            // 获取第一条任务
            WorkDetailTask task = null;
            if (CollectionUtils.isEmpty(workDetailTaskList)) {
                WorkDetailTask nextTask = new WorkDetailTask();
                nextTask.setMaterCode(apsWorkDetailNext.getMaterNo());
                nextTask.setMaterName(apsWorkDetailNext.getMaterName());
                nextTask.setApsWorkDetailId(apsWorkDetailNext.getId());
                nextTask.setPlanStartDateTime(apsWorkDetailNext.getPlanStartDateTime());
                nextTask.setPlanEndDateTime(apsWorkDetailNext.getPlanEndDateTime());
                nextTask.setGroupCode(apsWorkDetailNext.getGroupCode());
                nextTask.setPlmid(apsWorkDetailNext.getMaterNo());
                nextTask.setPhaseCode(apsWorkDetailNext.getPhaseCode());
                nextTask.setPhaseName(apsWorkDetailNext.getPhaseName());
                nextTask.setPrePhaseCode(apsWorkDetail.getPhaseCode());
                nextTask.setStatus(2);
                task = nextTask;

            } else {
                task = workDetailTaskList.get(0);
            }

            // 生成新任务
            WorkDetailTask newTask = MkBeanUtils.copyProperties(task, WorkDetailTask.class);
            newTask.setFinishCount(0);
            newTask.setFailCount(0);
            newTask.setStatus(2);
            newTask.setTotalCount(left > partExcept.getExceptCount() ? partExcept.getExceptCount() : left);
            newTask.setActualEndDateTime(null);
            newTask.setType(2);
            workDetailTaskMapper.insert(newTask);
            partExcept.setRemark(newTask.getTotalCount() + "生成任务数量");
            partExcept.setStatus(2);
            partExceptMapper.updateById(partExcept);
        }

    }

    public void delete(BaseIdReqVo reqVo) {
        partExceptMapper.deleteById(reqVo.getId());
    }
}
